define(['app'], function(app) {
	'use strict';

	var controller = function controller($scope, Searchpro_common,GoCatTypeAuth,Auth,GoDialog) {
		$scope.input = new Object();
		$scope.input.key='';
		$scope.input.brand_id ='';
		$scope.cat_type_id='';
		$scope.init_data = function(){
			Searchpro_common.common_goods($scope.input.key,$scope.input.brand_id,$scope.cat_type_id,function(data){
				$scope.datas = data;
			})
		}
		$scope.get_cat_type =function(){
		    if(!$scope.input.brand){
		        $scope.input.brand=new Object();
		        $scope.input.brand.id="";
		    }else{
			if($scope.input.cat3 && $scope.input.cat3.id != 0){
				$scope.cat_type_id = $scope.input.cat1.id+","+$scope.input.cat2.id+","+$scope.input.cat3.id;
			}else if($scope.input.cat2 && $scope.input.cat2.id != 0){
                $scope.cat_type_id = $scope.input.cat1.id+","+$scope.input.cat2.id;
			}else if($scope.input.cat1 && $scope.input.cat1.id != 0){
			    $scope.cat_type_id = $scope.input.cat1.id;
			}else{
			    $scope.cat_type_id
			}
			}

		}
		$scope.doSearch =function(){
			$scope.get_cat_type();
			/*console.log($scope.input.brand.id);
			console.log($scope.cat_type_id);*/
			Searchpro_common.common_goods($scope.input.key,$scope.input.brand.id,$scope.cat_type_id,function(data){
			    console.log(data);
				$scope.datas = data;
			});
		}
		//$scope.init_data()


		 /***分类三级联动***/
        //$scope.input=new Object();
        $scope.input.store_id = Auth.get_store_id(); //隐藏的企业id的绑定数据
		$scope.input.brand = {id:0,name:"请选择品牌"};
		$scope.input.cat1 = { id: 0, name: "请选择大分类" };
		$scope.input.cat2 = { id: 0, name: "请选择中分类" };
		$scope.input.cat3 = { id: 0, name: "请选择小分类" };

        //下拉侦听
        $scope.listen_brand = function(data, obj) {
			$scope.input.cat1 = { id: 0, name: "请选择大分类" };
			$scope.input.cat2 = { id: 0, name: "请选择中分类" };
			$scope.input.cat3 = { id: 0, name: "请选择小分类" };
        };
        $scope.listen_cat1 = function(data, obj) {
			$scope.input.cat2 = { id: 0, name: "请选择中分类" };
			$scope.input.cat3 = { id: 0, name: "请选择小分类" };
        };
        $scope.listen_cat2 = function(data, obj) {
            $scope.input.cat3 = { id: 0, name: "请选择小分类" };
        };
        //定义绑定
        var items_cat = new Array();
        var obj_brand = { name: 'input.brand' };
        var obj1_cat = { name: 'input.cat1' };
        var obj2_cat = { name: 'input.cat2' };
        var obj3_cat = { name: 'input.cat3' };
        items_cat.push(obj_brand);
        items_cat.push(obj1_cat);
        items_cat.push(obj2_cat);
        items_cat.push(obj3_cat);
		GoCatTypeAuth.init_load($scope, items_cat);
		$scope.doSelectBrand = function(){
			//id是值 name是显示
			GoDialog.showSelect("请选择品牌",$scope.brand_items,$scope.input.brand,function(data){
				$scope.input.brand_id = data.id;
				$scope.input.brand = data;
			});
		}
		$scope.doSelectCat1 = function(){
			//id是值 name是显示
			GoDialog.showSelect("大分类",$scope.cat1_items,$scope.input.cat1,function(data){
				$scope.input.cat1 = data;
			});
		}
		$scope.doSelectCat2 = function(){
			//id是值 name是显示
			GoDialog.showSelect("中分类",$scope.cat2_items,$scope.input.cat2,function(data){
				$scope.input.cat2 = data;
			});
		}
		$scope.doSelectCat3 = function(){
			//id是值 name是显示
			GoDialog.showSelect("小分类",$scope.cat3_items,$scope.input.cat3,function(data){
				$scope.input.cat3 = data;
			});
		}

	}

	controller.$inject = ['$scope', 'Searchpro_common','GoCatTypeAuth','Auth','GoDialog'];

	return app.registerController("searchpro_commonctrl",controller);
});